<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Adv_Model extends CI_Model{
    function __construct()
    {
        parent::__construct();
    }
    function getAllData($num,$offset){
        $query = $this->db->get('adv',$num,$offset);
      
        return $query->result();  
    } 
     function get_object($id)
    {
        $query = $this->db->get_where('adv', array('adv_id' =>$id));
        return $query->row();
    }
    function getNumData(){
        $query = $this->db->get('adv');
        return $query->num_rows();
    }
    function delete($id){
          $this->db->where('adv_id',$id);
          $query = $this->db->delete('adv');
          if($query){
              return true;
          }else{
              return false;
          }
    }
	function deleted($id){
          $this->db->where('adv_id',$id);
		  $data=array('bl_active'=>'-1');
          $query = $this->db->update('adv',$data);
          if($query){
              return true;
          }else{
              return false;
          }
    }
   function saveData($image_beauty_id,$data){
             if($image_beauty_id!=0){
                    $this->db->where('adv_id',$image_beauty_id);
                    if($this->db->update('adv',$data)){
                         return true;
                    }else{
                         return false;
                    }
             }else{
                    if($this->db->insert('adv',$data)){
                        return true;
                        
                    }else{
                        return false;
                    }
            }
    }
    function getNumAdv($arr_search){
            $this->db->join('adv_customer','adv.adv_customer_id = adv_customer.adv_customer_id');
            $this->db->join('adv_page','adv.adv_page_id = adv_page.adv_page_id');
            $this->db->join('adv_position','adv.adv_position_id = adv_position.adv_position_id');
            /*Begin search*/
            switch($arr_search['field_search'])
            {
                case 'adv_title':
                    $this->db->like('adv_title',$arr_search['key_search']);
                    break ;
            }
            /*End search*/
            $this->db->where('adv.bl_active',1);
            //$this->db->group_by('adv.adv_id');
             $query = $this->db->get('adv');
             return $query->num_rows();
    }
    function getAllAdv($num,$offset,$arr_search)
    {
        $this->db->select('adv.*,adv_customer.adv_customer_name,adv_page.adv_page_name,adv_position.adv_position_name');
        $this->db->join('adv_customer','adv.adv_customer_id = adv_customer.adv_customer_id');
        $this->db->join('adv_page','adv.adv_page_id = adv_page.adv_page_id');
        $this->db->join('adv_position','adv.adv_position_id = adv_position.adv_position_id');
            /*Begin search*/
            switch($arr_search['field_search'])
            {
                case 'adv_title':
                    $this->db->like('adv_title',$arr_search['key_search']);
                    break ;
            }
            /*End search*/
            $this->db->where('adv.bl_active',1);
            //$this->db->group_by('adv.adv_id');
            $query = $this->db->get('adv',$num,$offset);
            //echo $this->db->last_query();
             return $query->result();
    }
    function getAllAdvCustomer(){
        $this->db->where('bl_active',1);
        return $this->db->get('adv_customer')->result();
    }
    function getAllAdvPage(){
        $this->db->where('bl_active',1);
        $query = $this->db->get('adv_page');
        return $query->result();
   }
   function getAllAdvPosition(){
        $this->db->where('bl_active',1);
        $query = $this->db->get('adv_page');
        return $query->result();
   }
   function getAdvPositionByPage($adv_page_id){
       $this->db->where('adv_page_id',$adv_page_id); 
       $this->db->where('bl_active',1);
       $query = $this->db->get('adv_position');
       return $query->result();
   }
  }
?>
